package com.guodaxia.gzh.util;

import lombok.extern.slf4j.Slf4j;

import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Arrays;

/**
 * @author guojianquan
 * @date 2024/12/11 23:38
 */
@Slf4j
public class Sha1Util {


    public static String sha1(String input) {
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA-1");
            byte[] hash = digest.digest(input.getBytes("UTF-8"));
            StringBuilder hexString = new StringBuilder();
            for (byte b : hash) {
                String hex = Integer.toHexString(0xff & b);
                if (hex.length() == 1) hexString.append('0');
                hexString.append(hex);
            }
            return hexString.toString();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static String dictSortToString(String... inputs) {
        Arrays.sort(inputs);
        StringBuilder buf = new StringBuilder();
        for (String input : inputs) {
            buf.append(input);
        }
        return buf.toString();
    }
}
